﻿Imports MeoTom.Core.BLL
Imports Microsoft.ApplicationBlocks.Data

Namespace DAL
    Public Class CategoryProvider
        Inherits DataAccess
        Private util As New Utilities.Common()

        Public Sub New()

        End Sub

        Public Sub Create(ByVal Cat As Categories)
            Dim param(6) As SqlClient.SqlParameter
            param(0) = New SqlClient.SqlParameter("@Title", SqlDbType.NVarChar, 250)
            param(0).Value = util.NoHTML(Cat.Title)
            param(1) = New SqlClient.SqlParameter("@Description", SqlDbType.NVarChar, 350)
            param(1).Value = util.NoHTML(Cat.Description)
            param(2) = New SqlClient.SqlParameter("@SubCat", SqlDbType.Int, 4)
            param(2).Value = Cat.SubCat
            param(3) = New SqlClient.SqlParameter("@CatIndex", SqlDbType.Int, 4)
            param(3).Value = Cat.CatIndex
            param(4) = New SqlClient.SqlParameter("@TitleNone", SqlDbType.VarChar, 250)
            param(4).Value = util.utf8_to_ascii(util.NoHTML(Cat.Title))
            param(5) = New SqlClient.SqlParameter("@SiteID", SqlDbType.Int, 4)
            param(5).Value = Configs.SiteID

            SqlHelper.ExecuteNonQuery(strConn, CommandType.StoredProcedure, "Justin_ArticleCategory_Create", param)
        End Sub

        Public Sub Update(ByVal Cat As Categories)
            Dim param(6) As SqlClient.SqlParameter
            param(0) = New SqlClient.SqlParameter("@Title", SqlDbType.NVarChar, 50)
            param(0).Value = Cat.Title
            param(1) = New SqlClient.SqlParameter("@Description", SqlDbType.NVarChar, 350)
            param(1).Value = Cat.Description
            param(2) = New SqlClient.SqlParameter("@SubCat", SqlDbType.Int, 4)
            param(2).Value = Cat.SubCat
            param(3) = New SqlClient.SqlParameter("@CatIndex", SqlDbType.Int, 4)
            param(3).Value = Cat.CatIndex
            param(4) = New SqlClient.SqlParameter("@CatID", SqlDbType.Int, 4)
            param(4).Value = Cat.CatID
            param(5) = New SqlClient.SqlParameter("@TitleNone", SqlDbType.VarChar, 250)
            param(5).Value = util.utf8_to_ascii(util.NoHTML(Cat.Title))

            SqlHelper.ExecuteNonQuery(strConn, CommandType.StoredProcedure, "Justin_ArticleCategory_Update", param)
        End Sub

        Public Sub Delete(ByVal Cat As Categories)
            Dim param(2) As SqlClient.SqlParameter
            param(0) = New SqlClient.SqlParameter("@CatID", SqlDbType.Int, 4)
            param(0).Value = Cat.CatID
            param(1) = New SqlClient.SqlParameter("@SiteID", SqlDbType.Int, 4)
            param(1).Value = Configs.SiteID

            SqlHelper.ExecuteNonQuery(strConn, CommandType.StoredProcedure, "Justin_ArticleCategory_Delete", param)
        End Sub

        Public Function GetParentCat(ByVal Cat As Categories) As DataSet
            Dim param(2) As SqlClient.SqlParameter
            param(0) = New SqlClient.SqlParameter("@SubCat", SqlDbType.Int, 4)
            param(0).Value = Cat.SubCat
            param(1) = New SqlClient.SqlParameter("@SiteID", SqlDbType.Int, 4)
            param(1).Value = Configs.SiteID

            Return SqlHelper.ExecuteDataset(strConn, CommandType.StoredProcedure, "Justin_ArticleCategory_GetParent", param)
        End Function

        Public Function GetParentCat(ByVal ParentCat As Integer) As SqlClient.SqlDataReader
            Dim param(1) As SqlClient.SqlParameter
            param(0) = New SqlClient.SqlParameter("@SubCat", SqlDbType.Int, 4)
            param(0).Value = ParentCat
            param(1) = New SqlClient.SqlParameter("@SiteID", SqlDbType.Int, 4)
            param(1).Value = Configs.SiteID

            Return SqlHelper.ExecuteReader(strConn, CommandType.StoredProcedure, "Justin_ArticleCategory_GetParent", param)
        End Function

        Public Function GetByID(ByVal Cat As Categories) As SqlClient.SqlDataReader
            Dim param(2) As SqlClient.SqlParameter
            param(0) = New SqlClient.SqlParameter("@ID", SqlDbType.Int, 4)
            param(0).Value = Cat.CatID
            param(1) = New SqlClient.SqlParameter("@SiteID", SqlDbType.Int, 4)
            param(1).Value = Configs.SiteID

            Return SqlHelper.ExecuteReader(strConn, CommandType.StoredProcedure, "Justin_ArtileCategory_GetByID", param)
        End Function

    End Class
End Namespace
